﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework;

namespace Projeto3D
{
    class InputController
    {
        public KeyboardState keyboard;
        public KeyboardState oldKeyboard;
        public MouseState mouse;
        public MouseState oldMouse;

        public List<Keys> keysPressed;

        public InputController()
        {
            keysPressed = new List<Keys>();

            keyboard = Keyboard.GetState();
            mouse = Mouse.GetState();
        }

        public void getState()
        {
            oldKeyboard = keyboard;
            oldMouse = mouse;
            keyboard = Keyboard.GetState();
            mouse = Mouse.GetState();

            Keys[] keys = keyboard.GetPressedKeys();

            foreach (Keys keyPressed in keys)
            {
                if (!keysPressed.Contains(keyPressed))
                {
                    keysPressed.Add(keyPressed);
                }
            }

            foreach (Keys keyPressed in keysPressed)
            {
                if (keyboard.IsKeyUp(keyPressed))
                {
                    keysPressed.Remove(keyPressed);
                    break;
                }
            }
        }

        public bool isKeyJustPressed(Keys key)
        {
            if (keyboard.IsKeyDown(key) && oldKeyboard.IsKeyUp(key))
            {
                return true;
            }

            return false;
        }
    }
}
